load mnist_train

cls = unique(Yl);
c = size(cls,1);
[n,d] = size(Xl);
V = zeros(d,c);

for i = 1:c
    ix = find(Yl == cls(i));
    X = Xl(ix,:);
    [U,~] = svd(X',0);
    V(:,i) = U(:,1);
    imagesc(reshape(V(:,i),28,28));
    drawnow;
end
V = -V;
load mnist_test

VM = Xu*V;

[~,Yp] = max(VM,[],2);
Yp = Yp - 1;
calerr(Yp,Yu)

ix = find(Yp~=Yu);
for i = 1:length(ix)
    imagesc(reshape(Xu(ix(i),:),28,28))
    Yp(ix(i))
    Yu(ix(i))
    pause
end